﻿module MainApp

open System
open System.Windows
open System.Windows.Controls
open System.Windows.Input
open FSharpx
open Dom
open BrowserWindow
open View
open UriParsing
open DefaultDocument
open Loader
open Http


type MainWindow = XAML<"MainWindow.xaml">

let loadWindow() =    
    let window = MainWindow()
    let visual1 = window.Visual1 :> Controls.VisualHostControl

    let loader = Loader()
    let log = window.Log
    let writeLog txt = 
        log.Text <- log.Text + "\n" + txt

    let view = new DocumentViewController(visual1, window.ScrollViewer)    
    let controller = BrowserWindow(view.renderPage, loader, writeLog, navigator)
    controller.loadDocument(blankUri, defaultHtml)

    window.GoButton.Click |> Observable.add(fun args -> 
                   let btn = unbox<Button> args.Source
                   let url = window.AddressBox.Text;
                   controller.navigateUrl(url))

    window.Root.Loaded.Add(fun e->  
        ()         
    )
    window.Root

let win = new Window()
win.Title <- "Handle an Event"


[<STAThread>]
do (new Application()).Run(loadWindow()) |> ignore